Tutorial 8: Introducing Ecological Network Dynamics (BEFWM2)

Author

Danet and Becks, based on originals by Delmas and Griffiths

Published

February 14, 2023

Navigate to the GitHub location for the BioEnergetic Model.

It should look like this:

GitHubPageForBEFW

Then download to your Documents Folder the package.

DownloadTheZip

Once this folder is unzipped in your Documents Folder, you can install it using Pkg.develop.

using Pkg
Pkg.develop("~/Documents/EcologicalNetworksDynamics.jl-main/")
## My first BEFW Modelling

## Packages I need
using BEFWM2, DataFrames, Random, Plots, EcologicalNetworksPlots

## Time to do some Experiments!

Preamble

One of main advantages of running food web models in Julia is that simulations are fast and can be readily stored in your active project. With this in mind, make a new folder in your project called out_objects (right click > New Folder).

A first run of the Ecological Network Dynamics model (BEFW)

There are four major steps when running the BioEnergetic Food Web model in Julia. These should be familiar from our introduction to the DifferentialEquations package:

  1. Generate an initial food web network
  2. Set the parameters for each species in the network to generate the equations
  3. Simulate the network and equations
  4. Explore output and plot

While in the previous example with Differential Equations we assumed a simple 2-species network, one of the new activities here is to take advantage of a rich history of theory and tools to construct species rich networks with appropriate structural properties, such as connectance/complexity and levels of generalism/specialism and things the number of trophic levels and a body size distribtion of the species across trophic levels.

Step 1: generate an initial network

Here we make a foodweb, actually, a food chain, from an adjacency matrix with the FoodWeb method.

A = [0 0 0; 1 0 0; 0 1 0] # 1 basal producer ⋅ Species 2 eats 1 ⋅ Species 3 eats 2
foodweb = FoodWeb(A)
FoodWeb of 3 species:
  A: sparse matrix with 2 links
  M: [1.0, 1.0, 1.0]
  metabolic_class: 1 producers, 2 invertebrates, 0 vertebrates
  method: unspecified
  species: [s1, s2, s3]

Step 2: Generate the model parameters

Once the foodweb is created, the next step is to attribute values to the model parameters. This can be simply done by calling the method ModelParameters with foodweb as an argument.

# construct the equations and fixed parameters
# see below for body size dependent parameters etc
params = ModelParameters(foodweb)
ModelParameters{BioenergeticResponse}:
  foodweb: FoodWeb(S=3, L=2)
  environment: Environment(K=[1, nothing, nothing], T=293.15K)
  biorates: BioRates(e, r, x, y)
  functional_response: BioenergeticResponse

Step 3: Simulate biomass dynamics

Everything is ready to run the simulation, which can be simply done by calling simulate with the model parameters (params) and a vector species’ initial biomass (B0).

# create body sizes for each species
B0 = [0.5, 0.5, 0.5]

# use simulate function
# builds equations and uses DiffEq to run them!
sim = simulate(params, B0)
(ModelParameters = ModelParameters{BioenergeticResponse}(FoodWeb(S=3, L=2)), t = [0.0, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25  …  497.75, 498.0, 498.25, 498.5, 498.75, 499.0, 499.25, 499.5, 499.75, 500.0], B = [0.5 0.5 0.5; 0.3173572089866426 0.39004623698806057 0.6120393043271639; … ; 0.22059592602003045 0.18903427885098856 0.04884882983798568; 0.2205968780123746 0.18902425842300666 0.048850486337203645])

Step 4: Seeing the outputs!

Eventually you may want to plot the biomass dynamics - the trajectory - of your community to see what is happening. For our minimal example, it can be done as follows:

# create multiple objects: time = t and Bx = biomass for each species
# note how julia allows multiple things on left of = sign!
t, B1, B2, B3 = sim.t, sim.B[:,1], sim.B[:,2], sim.B[:,3]; # unpack variables

# Plot the basal species
plot(t, B1, lw = 3, label="Producer", xlabel = "Time", ylabel = "Biomass")
# add the herbivore
plot!(t, B2, lw = 3, label="Consumer")
# add the top predator
plot!(t, B3, lw = 3, label="Top consumer")

A More Complex Example

Step 1: Generae the initial network

In order to run the BEFW model with a more complex network, we have to construct an initial food web network (an adjacency matrix) using the niche model. The network is characterised by the number of species in the network and its connectance/complexity value.